package by.imotaeva.printing_services.services.impl;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.imotaeva.printing_services.dataaccess.PrintingProductOrderDao;
import by.imotaeva.printing_services.datamodel.Customer;
import by.imotaeva.printing_services.datamodel.OrderStatus;
import by.imotaeva.printing_services.datamodel.PrintingProductOrder;
import by.imotaeva.printing_services.services.PrintingProductOrderService;

@Service
public class PrintingProductOrderServiceImpl implements
		PrintingProductOrderService {
	private static final Logger LOGGER = LoggerFactory
			.getLogger(PrintingProductOrderServiceImpl.class);

	@Inject
	private PrintingProductOrderDao dao;

	@Override
	public PrintingProductOrder get(Long id) {

		return dao.getById(id);

	}

	@Override
	public void saveOrUpdate(PrintingProductOrder entity) {
		if (entity.getId() == null) {
			LOGGER.debug("Save new: {}", entity);
			dao.insert(entity);
		} else {
			LOGGER.debug("Update: {}", entity);
			dao.update(entity);
		}

	}

	@Override
	public void delete(PrintingProductOrder entity) {
		LOGGER.debug("Remove: {}", entity);
		dao.delete(entity.getId());

	}

	@Override
	public OrderStatus getStatusByProductionOrderNum(Long number) {
		return dao.getStatusByProductionOrderNum(number);
	}

	@Override
	public Customer getCustomerByProductionOrderNum(Long number) {
		return dao.getCustomerByProductionOrderNum(number);
	}

	@Override
	public void updateProductStatus(Long orderNumber, OrderStatus newStatus) {
		dao.updateProductStatus(orderNumber, newStatus);
	}

}
